home *** CD-ROM | disk | FTP | other *** search
/ Maclife 157 / MACLIFE157-2001-09.ISO.7z / MACLIFE157-2001-09.ISO / Linux / MacOS Tools / BootX 1.2.2 / Sources / src / miboot / miBoot_boot2.c < prev    next >
C/C++ Source or Header  |  2001-07-23  |  3KB  |  170 lines

  1. #include <Types.h>
  2. #include <Memory.h>
  3. #include <Quickdraw.h>
  4. #include <Fonts.h>
  5. #include <Events.h>
  6. #include <Menus.h>
  7. #include <Errors.h>
  8. #include <Files.h>
  9. #include <Devices.h>
  10. #include <Windows.h>
  11. #include <Traps.h>
  12.  
  13. #define RELOC        0
  14. #define TEST_PAINT    0
  15.  
  16. /* Low memory globals */
  17. #define    kLM_SysZone        0x2a6
  18. #define    kLM_ApplZone    0x2aa
  19. #define kLM_TheZone        0x118
  20. #define kLM_BootMask    0xb0e
  21. #define kLM_BootDrive    0x210
  22. #define kLM_CurrentA5    0x904
  23. #define kLM_BufPtr        0x10c
  24.  
  25. /* Increase system heap by this number of bytes */
  26. #define kSysZoneIncrease    0x200000 /* We ask for 2Mb */
  27.  
  28. extern void __Startup__(void);
  29. #if TEST_PAINT
  30. extern void test_paint(void);
  31. #endif
  32.  
  33. asm void __Startup__(void) {
  34.     /* First, the boot block code will have removed it's own
  35.        return address from the stack, we recover it */
  36.         subq.l        #4, sp
  37.         
  38. #if TEST_PAINT
  39.         jsr            test_paint
  40. #endif
  41.         
  42. #if RELOC
  43.     /* We copy ourselves on the stack */
  44.         movea.l        a3,a0
  45.         _GetHandleSize
  46.         lea          real_entry,a0
  47.         lea            __Startup__,a1
  48.         suba.l        a0,a1
  49.         add.l        a1,d0
  50.         suba.l        d0,sp
  51.         movea.l        sp,a1
  52.         _BlockMove
  53.         jmp            (a1)
  54. real_entry:    
  55.         move.l        a3,-(sp)
  56.         _ReleaseResource
  57.         move.l        sp, 0x908    /* CurStackBase */
  58. #endif
  59.  
  60.     /* This is in MacOS ... */
  61.         clr.l        0xa8c        /* RestProc */
  62.  
  63.     /* We backup any register we'll be using */
  64.         move.l        a2, -(sp)
  65.         move.l        a3, -(sp)
  66.         
  67.     /* We check if the Application heap and System heap are the
  68.        same. If they are not, then we move the application base
  69.        in order to increase the system zone size
  70.      */
  71.         movea.l        kLM_SysZone, a2
  72.         cmpa.l        kLM_ApplZone, a2
  73.         beq            same_zone
  74.         movea.l        (a2), a0
  75.         adda.l        #kSysZoneIncrease, a0
  76.         _SetAppBase
  77. same_zone:
  78.         
  79.     /* Set the current zone to be the system zone */
  80.         move.l        a2, kLM_TheZone
  81.     
  82. #if !RELOC
  83.     /* Detach ourselves (we should already be locked) */
  84.         move.l        a3, -(sp)
  85.         _DetachResource
  86. #endif
  87.     
  88.     /* Load the second code resource */
  89.         subq.l        #4, sp
  90.         pea            'boot'
  91.         move.w        #3, -(sp)
  92.         _GetResource
  93.         move.l        (sp)+, a2
  94.         cmpa.l        #0, a2
  95.         beq            load_error
  96.     
  97.     /* Detach, move high and lock the resource. We don't use HLockHi, may not
  98.        be in ROM */
  99.         move.l        a2, -(sp)
  100.         _DetachResource
  101.         movea.l        a2, a0
  102.         _MoveHHi
  103.         movea.l        a2, a0
  104.         _HLock
  105.     
  106.     /* Call the resource' code */
  107.         move.l        (a2), a0
  108.         move.l        kLM_BufPtr, -(sp)
  109.         move.l        kLM_CurrentA5, -(sp)
  110.         move.l        a5, -(sp)
  111.         jsr            (a0)
  112.         move.l        (sp)+, a5
  113.         move.l        (sp)+, kLM_CurrentA5
  114.         move.l        (sp)+, kLM_BufPtr
  115.         
  116.     /* We got out of the booter, we must tell MacOS not to try booting
  117.        from this partition */
  118.         move.w        kLM_BootMask, d0
  119.         move.w        kLM_BootDrive, d1
  120.         bclr        d1, d0
  121.         move.w        d0, kLM_BootMask
  122.         
  123.     /* Get rid of the boot resource and unlock myself*/
  124.         movea.l        a2, a0
  125.         _DisposeHandle
  126. #if !RELOC
  127.         movea.l        a3, a0
  128.         _HUnlock
  129. #endif
  130.     
  131.     /* result code */
  132. //        moveq        #dsBadStartupDisk, d0
  133. //        moveq        #0, d0
  134.         moveq        #dsOldSystem, d0
  135.         _SysError
  136.             
  137.     /* Exit (restore registers and return) */
  138. exit:
  139.         movea.l        (sp)+, a3
  140.         movea.l        (sp)+, a2
  141.         rts
  142.  
  143. load_error:    
  144.         moveq        #dsBadStartupDisk, d0
  145.         bra.s        exit
  146. }
  147.  
  148. #if TEST_PAINT
  149.  
  150. void test_paint(void)
  151. {
  152.     GDHandle    hdl;
  153.     PixMapPtr    pm;
  154.     UInt32        x,y;
  155.     
  156.     hdl = LMGetMainDevice();
  157.     if (hdl == NULL || (**hdl).gdPMap == NULL)
  158.         return;
  159.     pm = *(**hdl).gdPMap;
  160.     if (pm->baseAddr == NULL)
  161.         return;
  162.     
  163.     for(y=100; y<200; y++) {
  164.         unsigned char* line = (unsigned char*)pm->baseAddr + y * (pm->rowBytes & 0x3fff);
  165.         for (x=100; x<500; x++)
  166.             line[x] = 0;
  167.     }
  168. }
  169.  
  170. #endif